package com.ruoyi.workbench.service.impl;

import com.ruoyi.workbench.domain.WorkContent;
import com.ruoyi.workbench.mapper.WorkContentMapper;
import com.ruoyi.workbench.service.WorkContentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工作内容(WorkContent)表服务实现类
 *
 * @author makejava
 * @since 2024-07-04 10:53:03
 */
@Service("workContentService")
public class WorkContentServiceImpl implements WorkContentService {
    @Resource
    private WorkContentMapper workContentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param workContentId 主键
     * @return 实例对象
     */
    @Override
    public WorkContent queryById(Long workContentId) {
        return this.workContentDao.queryById(workContentId);
    }

    /**
     * 分页查询
     *
     * @param workContent 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
//    @Override
//    public Page<WorkContent> queryByPage(WorkContent workContent, PageRequest pageRequest) {
//        long total = this.workContentDao.count(workContent);
//        return new PageImpl<>(this.workContentDao.queryAllByLimit(workContent, pageRequest), pageRequest, total);
//    }

    /**
     * 新增数据
     *
     * @param workContent 实例对象
     * @return 实例对象
     */
    @Override
    public WorkContent insert(WorkContent workContent) {
        this.workContentDao.insert(workContent);
        return workContent;
    }

    @Override
    public int insertBatch(List<WorkContent> entities) {
        return this.workContentDao.insertBatch(entities);
    }

    /**
     * 修改数据
     *
     * @param workContent 实例对象
     * @return 实例对象
     */
    @Override
    public WorkContent update(WorkContent workContent) {
        this.workContentDao.update(workContent);
        return this.queryById(workContent.getWorkContentId());
    }

    /**
     * 通过主键删除数据
     *
     * @param workContentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long workContentId) {
        return this.workContentDao.deleteById(workContentId) > 0;
    }
}
